package com.sss.myspringsecurity.config.securityconfig.handler;

import com.alibaba.fastjson.JSON;
import com.sss.myspringsecurity.util.ResponseDataEnum;
import com.sss.myspringsecurity.util.Result;
import com.sss.myspringsecurity.util.ServletUtils;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 处理账号被挤下线处理逻辑
 * @author sss
 * @date 2020-02-10 16:04
 **/
@Component
public class CustomerSessionInformationExpiredStrategy implements SessionInformationExpiredStrategy {
    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent sessionInformationExpiredEvent) throws IOException, ServletException {
        HttpServletResponse response = sessionInformationExpiredEvent.getResponse();
        ServletUtils.renderString(response, JSON.toJSONString(Result.fail(ResponseDataEnum.ACCOUNTFORCEDBACK)));
    }
}
